package com.taoyi.mhouse.fragments;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.tempo.widget.LoadingView;

/**
 * @author tempo
 *         on 2015/11/23.
 */
public  abstract class LoadingFragment<T> extends BaseFragment {
    private LoadingView mLoadingView;
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        mLoadingView=new ContainerView(getActivity().getApplicationContext());
        return mLoadingView;
    }

    @Override
    public void onResume() {
        super.onResume();
        mLoadingView.startLoad();
    }
    private class ContainerView extends LoadingView<T> {
        public ContainerView(Context context) {
            super(context);
        }
        @Override
        protected View getSuccessView(Context context, T data) {
            return LoadingFragment.this.getSuccessView(context,data);
        }
        @Override
        protected void loadData(LoadingCallback callback) {
            LoadingFragment.this.loadData(callback);
        }
    }
    protected abstract void  loadData(LoadingView.LoadingCallback callback);
    protected abstract View getSuccessView(Context context,T data);
}
